from rest_framework import serializers

from .search_indexes import SKUIndex
from .models import SKU
from drf_haystack.serializers import HaystackSerializer


class SKUSerializers(serializers.ModelSerializer):
    """商品的序列化器"""
    class Meta:
        model = SKU
        fields = ['id', 'price', 'name', 'default_image_url', 'comments']


class SKUIndexSerializers(HaystackSerializer):
    """
    SKU索引结果数据序列化器
    """
    object = SKUSerializers(read_only=True)

    class Meta:
        index_classes = [SKUIndex]
        fields = ('text', 'object')





